<?php
    //删除操作
    header('content-type:text/html;charset="utf-8"');
    //定义统一返回格式
    $responseData = array("code" => 0,"message" => "");

    //删除的数据
    $id = $_POST['id'];

    //1.连接数据库
    $link = mysqli_connect("localhost","root","root");

    //2.判断是否连接成功
    if(!$link){
        $responseData['code'] = 1;
        $responseData['message'] = "数据库连接失败";
        //返回到前台页面
        echo json_encode($responseData);
        exit; //结束后续操作
    }

    //3.设置字符集
    mysqli_set_charset($link,"utf8");

    //4.选择数据库
    mysqli_select_db($link,"租售系统");

    //5.准备sql语句进行删除操作
    $sql = "DELETE FROM goods WHERE id={$id}";

    //6.发送sql语句
    $res = mysqli_query($link,$sql);

    //7.处理结果集
    if(!$res){
        $responseData['code'] = 2;
        $responseData['message'] = "数据删除失败";
        //返回到前台页面
        echo json_encode($responseData);
        exit; //结束后续操作
    }else{
        $responseData['message'] = "数据删除成功";
        echo json_encode($responseData);
    }

    //8.关闭数据库
    mysqli_close($link);
?>